var express = require('express');
var router = express.Router();
const goodsController = require("../controllers/goods_controller")
const mongoUtil = require("../models/mongo_util")
const goodsModel = require("../models/goods_model")
// 添加商品
var goods = {
    goodsId: 1,
    name: "电灯",
    price: 124,
    Unsalable:0
}
router.post("/addgoods", (req, res) => {
    // var {
    //     goods
    // }=req.body
    goodsController.Addgoodslist(goods, (result) => {

        res.json(result)
    })
})
//查询商品
router.post("/getAllgoods", (req, res) => {
    var {
       page,pagesize
    }=req.body
    goodsController.getAllgoodslist({page,pagesize}, (result) => {

        res.json(result)
    })
})
// 修改商品
router.put("/putgoods", (req, res) => {
    var {
        goodsId,
        // goods
    } = req.body
    const goodslist = {
        "goodsId": goodsId,
        "goods": goods
    }
    goodsController.putgoods(goodslist, (result) => {
        res.json(result)
    })
})
//商品下架Unsalable
router.put("/goodsUnsalable", (req, res) => {
    var {
        goodsId,
        // goods
        Unsalable
    } = req.body
    const goodslist = {
        "goodsId": goodsId,
        "Unsalable": Unsalable
    }
    goodsController.putgoodsUnsalable(goodslist, (result) => {
        res.json(result)
    })
})
//
module.exports = router